﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace Tzx.Tools.Payroll2Images.Exe
{
    /// <summary>
    /// 
    /// </summary>
    public partial class MainFrm : Form
    {
        /// <summary>
        /// 
        /// </summary>
        public MainFrm()
        {
            InitializeComponent();

            //
            Load += MainFrm_Load;
            TsbtnDing.Click += (object sender, EventArgs e) =>
            {
                //钉住
                bool checked_new = !TsbtnDing.Checked;
                TsbtnDing.Checked = checked_new;
                TsbtnDing.CheckState = checked_new ? CheckState.Checked : CheckState.Unchecked;
                TopMost = checked_new;
                TsbtnDing.BackColor = checked_new ? Color.Yellow : SystemColors.Control;
            };

            //下一步
            ucExcelToTable1.NextClick += UcExcelToTable1_NextClick;
            //下一步
            ucOneRowToReport1.NextClick += UcOneRowToReport1_NextClick;
        }

        /// <summary>
        /// 加载时
        /// </summary>        
        void MainFrm_Load(object sender, EventArgs e)
        {
            Text = App.Title + "【编译" + App.Version_Date + " " + App.Version_Time + "】";
            Icon = Properties.Resources.Icon_DataDistribution;
        }

        /// <summary>
        /// 下一步1
        /// </summary>        
        private void UcExcelToTable1_NextClick(object sender, EventArgs e)
        {
            //导入数据
            DataTable data = ucExcelToTable1.ExcelTable;
            if (data == null)
            {
                MessageBox.Show("没有数据表", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //
            tabMain.SelectedTab = tp2_Preview;//
            ucOneRowToReport1.SetData(data);//报表
        }

        /// <summary>
        /// 下一步2
        /// </summary>        
        private void UcOneRowToReport1_NextClick(object sender, EventArgs e)
        {
            //传入待发送文件夹路径
            string dir = ucOneRowToReport1.GetExportDirectory();
            if (string.IsNullOrEmpty(dir))
            {
                MessageBox.Show("没有导出文件夹，请先导出。", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (!Directory.Exists(dir))
            {
                MessageBox.Show("指定文件夹【" + dir + "】不存在", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //
            tabMain.SelectedTab = tp3_Send;//
            //ucSender1.SendDirectory(dir);//文件目录
            ucSenderV21.SendDirectory(dir);//文件目录
        }

        
                
    }
}
